import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/RouteAct.dart';
import '../../l10n/messages.dart';
import 'SuccessfullyUnboundCard.dart';

class VerifyBankCardIdentity extends StatefulWidget {
  const VerifyBankCardIdentity({super.key});

  @override
  State<VerifyBankCardIdentity> createState() => _VerifyBankCardIdentityState();
}

class _VerifyBankCardIdentityState extends State<VerifyBankCardIdentity> {
  List<TextEditingController> _controllers = List.generate(6, (index) => TextEditingController());
  String password="";
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(

      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text('解绑银行卡',style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
      ),
      body: ListView(
        children: [
          SizedBox(height: 44.h,),
          Center(
            child:  Text("请输入支付密码，以验证身份",style: TextStyle(color: Colors.black,fontSize: 16.sp),),
          ),

            SizedBox(height: 18.h,),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: List.generate(6, (index) {
                    return Container(
                      width: 40.0.w,
                      height: 40.0.h,

                      child: TextField(
                        controller: _controllers[index],
                        autofocus: true,
                        textAlign: TextAlign.center,
                        obscureText: true,
                        keyboardType: TextInputType.number,
                        maxLength: 1,
                        style: TextStyle(color: Colors.black),
                        onChanged: (value) {
                          // 自动切换到下一个输入框
                          if (value.isNotEmpty) {
                            if (index < _controllers.length - 1) {
                              FocusScope.of(context).nextFocus();
                              password +=value;
                              print(password);
                            }
                            if (index == _controllers.length-1){
                              password +=value;
                              Navigator.push( context, FadeRoute(page:SuccessfullyUnboundBankCard()));

                            }



                          } else {
                            // 删除时自动切换到上一个输入框
                            if (index > 0) {
                              FocusScope.of(context).previousFocus();
                            }
                          }
                        },
                        decoration: InputDecoration(
                          counterText: '',
                          contentPadding: EdgeInsets.all(12.0),
                          border: OutlineInputBorder(),
                          enabledBorder: OutlineInputBorder(
                            borderSide: BorderSide(color:MyColors.hintColor, width: 1.0),
                            borderRadius: BorderRadius.zero, // 设置为零以去除圆角
                          ),
                          focusedBorder: OutlineInputBorder(
                            borderSide: BorderSide(color:MyColors.hintColor, width: 1.0),
                            borderRadius: BorderRadius.zero, // 设置为零以去除圆角
                          ),
                        ),
                      ),
                    );
                  }),
                ),
              SizedBox(height: 16.h,),
              Center(
                child:GestureDetector(
                  child: Text("忘记密码？",style: TextStyle(color: MyColors.themeColor,fontSize: 12.sp),),
                  onTap: (){

                  },
                ),
              ),
              ],

          ),


    );
  }

}
